﻿using Sustainalytics.Entities;
using Sustainalytics.Entities.ESGRatings;
using System;

namespace Sustainalytics.ScreeningTool.Service
{
    /// <summary>
    /// Used for Displaying
    /// </summary>
    public class FilterDto
    {
        //less data
        public Guid Id { get; set; }
        public string Name { get; set; }
        public FilterType Type { get; set; }
        public Guid OwnerUserId { get; set; }
        public bool IsCurrentUserOwner { get; set; }
        public Guid AccountId { get; set; }
        public DateTime? LastSaved { get; set; }
        public DateTime CreatedAt { get; set; }
        public bool IsFavorite { get; set; }
        public FilterStatus Status { get; set; }
        public DateTime? PublishDate { get; set; }
        public DateTime? UnPublishDate { get; set; }
        public bool Shared { get; set; }
        public TargetType TargetType { get; set; }
        public Guid AssociatedUserId { get; set; }
        public ExportType? ExportType { get; set; }

        //extended
        public Guid? PortfolioId { get; set; }
        public string PortfolioName { get; set; }

        public int? UniverseId { get; set; }
        public string UniverseName { get; set; }

        public Guid? PeerGroup { get; set; }
        public string PeerGroupName { get; set; }

        public Guid? Region { get; set; }
        public string RegionName { get; set; }

        public Guid? Country { get; set; }
        public string CountryName { get; set; }

        public CompanyTypeEnum? CompanyType { get; set; }
        public string CompanyTypeName { get; set; }

        public Guid? WeightMatrixId { get; set; }
        public string WeightMatrixName { get; set; }

        public Guid? ReferenceUniverseId { get; set; }
        public string ReferenceUniverseName { get; set; }
        public ComparativeGroupEnum? ComparativeGroup { get; set; }
        public int? CompanyTypePublicOrPrivate { get; set; }
        public int? ResearchType { get; set; }
        public int? CriteriaCount { get; set; }
   
        public static FilterDto ToFilterDto(Guid currentUserId, Filter filter, bool includeAllDetails, int criteriaCount = 0)
        {
            if (includeAllDetails)
            {
                var filterDto = new FilterDto
                {
                    Id = filter.Id,
                    Name = filter.Name,
                    Type = filter.Type,
                    OwnerUserId = filter.OwnerUserId,
                    IsCurrentUserOwner = filter.OwnerUserId == currentUserId,
                    AccountId = filter.AccountId,
                    Shared = filter.Type == FilterType.Shared,
                    LastSaved = filter.LastSaved,
                    CreatedAt = filter.CreatedAt,
                    IsFavorite = filter.IsFavorite,
                    Status = filter.Status,
                    TargetType = filter.TargetType,
                    ExportType = filter.ExportType,

                    //include extended
                    PortfolioId = filter.PortfolioId,
                    PortfolioName = filter.PortfolioName,

                    UniverseId = filter.UniverseId,
                    UniverseName = filter.UniverseName,

                    PeerGroup = filter.PeerGroup,
                    PeerGroupName = filter.PeerGroupName,

                    Region = filter.Region,
                    RegionName = filter.RegionName,

                    Country = filter.Country,
                    CountryName = filter.CountryName,

                    CompanyType = filter.CompanyType,
                    CompanyTypeName = filter.CompanyType.ToString(),

                    WeightMatrixId = filter.WeightMatrixId,
                    WeightMatrixName = filter.WeightMatrixName,

                    ReferenceUniverseId = filter.ReferenceUniverseId,
                    ReferenceUniverseName = filter.ReferenceUniverseName,

                    ComparativeGroup = filter.ComparativeGroup,
                    CompanyTypePublicOrPrivate = filter.CompanyTypePublicOrPrivate,
                    ResearchType = filter.ResearchType,
                    CriteriaCount = criteriaCount
                };

                return filterDto;
            }
            
            //basic data for Screening tool landing page
            return  new FilterDto {
                Id = filter.Id,
                Name = filter.Name,
                Type = filter.Type,
                OwnerUserId = filter.OwnerUserId,
                IsCurrentUserOwner = filter.OwnerUserId == currentUserId,
                Shared = filter.Type == FilterType.Shared,
                LastSaved = filter.LastSaved,
                IsFavorite = filter.IsFavorite,
                Status = filter.Status,
                TargetType = filter.TargetType
            };
        }
    }
}
